package org.worthydots.access.jpa.dao;

import java.util.List;

import org.worthydots.access.jpa.entity.TrainSchedule;

public class TrainScheduleDAOImpl extends DAOImpl implements TrainScheduleDAO {

	public TrainScheduleDAOImpl() {
		super();
	}
	
	public void saveTrainSchedule(TrainSchedule trainSchedule) {
		entityManager.getTransaction().begin();
		entityManager.merge(trainSchedule);
		entityManager.getTransaction().commit();
	}
	
	public void saveTrainScheduleIfNotPresent(TrainSchedule trainSchedule) {
		TrainSchedule trainScheduleInDB = getTrainScheduleByTrainNumber(trainSchedule.getTrainNumber());
		if (trainScheduleInDB == null)
			saveTrainSchedule(trainSchedule);
	}

	public TrainSchedule getTrainScheduleByTrainNumber(String trainNumber) {
		return entityManager.find(TrainSchedule.class, trainNumber);
	}

	public List<TrainSchedule> getAllTrainSchedules() {
		// TODO Auto-generated method stub
		return null;
	}
}
